package com.lechuang.goods.service.impl;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lechuang.common.request.PageRequest;
import com.lechuang.goods.dto.GoodsListDTO;
import com.lechuang.goods.entity.GoodsSpu;
import com.lechuang.goods.service.GoodsSpuService;
import com.lechuang.goods.mapper.GoodsSpuMapper;
import org.springframework.stereotype.Service;

import java.util.List;

/**
* @author apple
* @description 针对表【goods_spu(商品spu)】的数据库操作Service实现
* @createDate 2024-06-22 11:12:06
*/
@Service
public class GoodsSpuServiceImpl extends ServiceImpl<GoodsSpuMapper, GoodsSpu>
    implements GoodsSpuService{

    @Override
    public Page<GoodsSpu> pageList(PageRequest<GoodsListDTO> pageRequest) {
        Page<GoodsSpu> page = new Page<>(pageRequest.getPageNum(), pageRequest.getPageSize());

        GoodsListDTO goodsListDTO = pageRequest.getQuery();
        return this.lambdaQuery()
                .eq(goodsListDTO.getGoodsStatus() != null, GoodsSpu::getGoodsStatus, goodsListDTO.getGoodsStatus())
                .eq(goodsListDTO.getTenantId() != null, GoodsSpu::getTenantId, goodsListDTO.getTenantId())
                .eq(goodsListDTO.getCategoryId() != null, GoodsSpu::getCategoryId, goodsListDTO.getCategoryId())
                .and(StrUtil.isNotEmpty(goodsListDTO.getSelectText()), tmp ->
                        tmp.like(GoodsSpu::getTitle, goodsListDTO.getSelectText())
                                .or()
                                .like(GoodsSpu::getName, goodsListDTO.getSelectText())
                )
                .page(page);
    }

    @Override
    public List<GoodsSpu> getByIds(List<Long> idList) {
        return this.lambdaQuery()
                .in(GoodsSpu::getId, idList)
                .list();
    }
}




